package com.css.bjdt_core.partyItemCount.service;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.nutz.dao.Dao;
import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Sql;
import org.nutz.dao.sql.SqlCallback;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.css.bjdt_core.partyItemCount.dao.PartyItemCountDao;
import com.css.bjdt_core.partyItemCount.entity.PartyItemCountData;
import com.css.bjdt_core.reportFill.entity.RptCellCommentEntity;

@Service
public class PartyItemCountService {
	@Autowired
	private PartyItemCountDao partyItemCountDao;
	
	@Autowired
	private Dao dao;
	 

	public List<PartyItemCountData> selectPartyItemAgeCount(String dzzId) {
		if (StringUtils.isBlank(dzzId) ) {
			return null;
		}
	
		return partyItemCountDao.selectPartyItemAgeCount(dzzId);

	}
	
	/**
	 * 按年龄段统计党组织年龄
	 * 2019-9-22
	 * */
	public PartyItemCountData selectPartyItemAgeCount2(String dzzId) {
		if (StringUtils.isBlank(dzzId) ) {
			return null;
		}
	
		return partyItemCountDao.selectPartyItemAgeCount2(dzzId);

	}

	/**
	 * 按区段统计党组织入党时间
	 * 2019-9-22
	 * 
	 * 
	 * */
	public PartyItemCountData selectPartyItemRdsjCount(String dzzId) {
		if (StringUtils.isBlank(dzzId) ) {
			return null;
		}
	
		return partyItemCountDao.selectPartyItemRdsjCount(dzzId);

	}
	
	/**
	 * 按学历段统计党组织学历
	 * 2019-9-22
	 * 
	 * 
	 * */
	public PartyItemCountData selectPartyItemEducationCount(String dzzId) {
		if (StringUtils.isBlank(dzzId) ) {
			return null;
		}
	
		return partyItemCountDao.selectPartyItemEducationCount(dzzId);

	}
	
	/**
	 * 按工作岗位统计党组织
	 * 2017-9-25
	 * */
	public PartyItemCountData selectPartyItemJobCount(String dzzId) {
		if (StringUtils.isBlank(dzzId) ) {
			return null;
		}
	
		return partyItemCountDao.selectPartyItemJobCount(dzzId);

	}
	
	public List<String> getPersonList(String sql,String[] ids){
		Sql strSql = Sqls.create(sql);
		strSql.params().set("dzzid", ids);
		strSql.setCallback(new SqlCallback() {
			@Override
			public Object invoke(Connection conn, ResultSet rs, Sql strSql) throws SQLException {
				List<String> pesonList = new ArrayList<String>();
				while (rs.next()) {
					pesonList.add(rs.getString("DY_ID"));
				}
				return pesonList;
			}
		});
		dao.execute(strSql);
		return strSql.getList(String.class);
	}
}
